package com.lmpop.createIndex.search;

import com.lmpop.createIndex.searchModel.Queue;
import com.lmpop.createIndex.searchModel.QueueValue;
import com.lmpop.createIndex.searchModel.SearchData;
import com.lmpop.createIndex.searchModel.SearchModel;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MidNavIndexFiles
{
  public ProperUtil properUtil;
  private String file_path;

  public MidNavIndexFiles()
  {
    this.properUtil = new ProperUtil();
    this.file_path = this.properUtil.getFilePathByModel("nav");
  }

  public List getMidNavInfo(Map paraMap) throws IOException {
    ArrayList showList = new ArrayList();
    SearchData search = new SearchData();
    ArrayList paraList = new ArrayList();

    String cust_id = ""; String ifshow = ""; String nav_post = ""; String sort_order = ""; String start_sort = ""; String end_sort = "";
    if (paraMap.get("cust_id") != null) cust_id = paraMap.get("cust_id").toString();
    if (paraMap.get("ifshow") != null) ifshow = paraMap.get("ifshow").toString();
    if (paraMap.get("nav_post") != null) nav_post = paraMap.get("nav_post").toString();
    if (paraMap.get("start_sort") != null) start_sort = paraMap.get("start_sort").toString();
    if (paraMap.get("end_sort") != null) end_sort = paraMap.get("end_sort").toString();

    Queue queue = new Queue(new QueueValue[] { new QueueValue("sort_order", 2, true) });
    paraList.add(new SearchModel("0", "cust_id", cust_id));//100000000000000
    paraList.add(new SearchModel("0", "ifshow", ifshow));//0
    paraList.add(new SearchModel("0", "nav_post", nav_post));//2

    showList = search.getSearchInfo(this.file_path, paraList, queue);
    return showList;
  }

  public String addZeroByLeft(String sort_order) {
    if (sort_order.equals("")) return "";
    int sort_len = sort_order.length();
    int add_len = 0;
    if (sort_len < 11) {
      add_len = 11 - sort_len;
    }
    String zeroStr = "";
    for (int i = 0; i < add_len; i++) {
      zeroStr = zeroStr + "0";
    }
    return zeroStr + sort_order;
  }
}